package com.squareup.picasso;

import android.view.ViewTreeObserver;
import android.widget.ImageView;

import java.lang.ref.WeakReference;

final class DeferredRequestCreator implements ViewTreeObserver.OnPreDrawListener {
    WeakReference<ImageView> target;

    public final boolean onPreDraw() {
        RequestCreator requestCreator = null;
        ImageView target = this.target.get();
        if (target != null) {
            ViewTreeObserver vto = target.getViewTreeObserver();
            if (vto.isAlive()) {
                int width = target.getWidth();
                int height = target.getHeight();
                if (width > 0 && height > 0) {
                    vto.removeOnPreDrawListener(this);
                    requestCreator.deferred = false;
                    requestCreator.resize(width, height).into(target, null);
                }
            }
        }
        return true;
    }
}

